package com.wdm.sms.commonutil.config.inteceptor.jwt;

import com.wdm.sms.commonutil.config.inteceptor.jwt.MyJwtInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author: wudaiming
 * @date: 2023/3/13
 * @description: JWT拦截配置
 * @version: 1.0
 */

//@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(jwtInterceptor())
                .excludePathPatterns("/login")
                .excludePathPatterns("/loginOut")
                //放行swaggera
                .excludePathPatterns("/swagger-resources/**","/swagger/**","/swagger-ui.html")
                //拦截所有请求，通过判断token来决定是否需要登陆，有@PassToken注解的方法可以不需要token
                .addPathPatterns("/**");
    }

    @Bean
    public MyJwtInterceptor jwtInterceptor(){
        return new MyJwtInterceptor();
    }
}